<?php

use Faker\Factory as Faker;
use App\Models\ItemOrder;
use App\Repositories\ItemOrderRepository;

trait MakeItemOrderTrait
{
    /**
     * Create fake instance of ItemOrder and save it in database
     *
     * @param array $itemOrderFields
     * @return ItemOrder
     */
    public function makeItemOrder($itemOrderFields = [])
    {
        /** @var ItemOrderRepository $itemOrderRepo */
        $itemOrderRepo = App::make(ItemOrderRepository::class);
        $theme = $this->fakeItemOrderData($itemOrderFields);
        return $itemOrderRepo->create($theme);
    }

    /**
     * Get fake instance of ItemOrder
     *
     * @param array $itemOrderFields
     * @return ItemOrder
     */
    public function fakeItemOrder($itemOrderFields = [])
    {
        return new ItemOrder($this->fakeItemOrderData($itemOrderFields));
    }

    /**
     * Get fake data of ItemOrder
     *
     * @param array $postFields
     * @return array
     */
    public function fakeItemOrderData($itemOrderFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'channel_id' => $fake->randomDigitNotNull,
            'channel_order_id' => $fake->randomDigitNotNull,
            'house_id' => $fake->randomDigitNotNull,
            'wechat_user_id' => $fake->randomDigitNotNull,
            'consult_content' => $fake->word,
            'status' => $fake->randomDigitNotNull,
            'updated_at' => $fake->word,
            'created_at' => $fake->word
        ], $itemOrderFields);
    }
}
